﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace Juli.Mes.MongoDb.Attributes
{
    public class MongoTableAttribute : Attribute
    {
        public string TableName { get; set; }

        public bool IsMonthlyBasis { get; set; }

        public bool IsDaylyBasis { get; set; }

        public MongoTableAttribute(string tableName, bool isMonthlyBasis = false, bool isDaylyBasis = false)
        {
            this.TableName = tableName;
            this.IsMonthlyBasis = isMonthlyBasis;
            this.IsDaylyBasis = isDaylyBasis;
        }

        public string GetTableName()
        {
            if (this.IsMonthlyBasis && !this.IsDaylyBasis)
            {
                DefaultInterpolatedStringHandler interpolatedStringHandler = new DefaultInterpolatedStringHandler(0, 2);
                interpolatedStringHandler.AppendFormatted(this.TableName);
                interpolatedStringHandler.AppendFormatted<DateTime>(DateTime.Now, "yyyyMM");
                return interpolatedStringHandler.ToStringAndClear();
            }

            if (this.IsMonthlyBasis || !this.IsDaylyBasis)
                return this.TableName;

            DefaultInterpolatedStringHandler interpolatedStringHandler1 = new DefaultInterpolatedStringHandler(0, 2);
            interpolatedStringHandler1.AppendFormatted(this.TableName);
            interpolatedStringHandler1.AppendFormatted<DateTime>(DateTime.Now, "yyyyMMdd");
            return interpolatedStringHandler1.ToStringAndClear();
        }
    }
}
